<?php

  /*
   * Validaiton for Document content
   */

  function  rules_form_validation($form) {

	// maximum length validation for Title and Description Field
    maxlength_validation($form['title']['#value'], 255, $form['title']['#title'], 'title');

    // Bad character validations
    chkbadchar($form['title']['#value'], $form['title']['#title'], 'title');
    chkbadchar($form['rules_field_keyword']['und'][0]['value']['#value'],
                                            $form['rules_field_keyword']['und'][0]['value']['#title'], 'rules_field_keyword');
	chkbadchar($form['rules_field_des']['und'][0]['value']['#value'],
                                            $form['rules_field_des']['und'][0]['value']['#title'], 'rules_field_des');
   	//chkbadchar($form['field_rules_url'][0]['value']['#value'],$form['field_rules_url']['#title'],'field_rules_url');
	chkbadchar($form['rules_field_short']['und'][0]['value']['#value'], $form['rules_field_short']['und'][0]['value']['#title'], 'rules_field_short');
	chkbadchar($form['rules_field_titleact']['und'][0]['value']['#value'], $form['rules_field_titleact']['und'][0]['value']['#title'], 'rules_field_titleact');

	// minimum length charcter
  	minilength_validation($form['title']['#value'], 5, $form['title']['#title'], 'title');
  	minilength_validation($form['rules_field_keyword']['und'][0]['value']['#value'], 5, $form['rules_field_keyword']['und'][0]['value']['#title'],'rules_field_keyword');
  	minilength_validation($form['rules_field_des']['und'][0]['value']['#value'], 5, $form['rules_field_des']['und'][0]['value']['#title'], 'rules_field_des');

	//Date Validation
	check_scheduler_date_expire($form['scheduler_settings']['unpublish_on']['date']['#value'],'unpublish_on');
	check_date_expire($form['field_rules_date_released']['und'][0]['value']['date']['#value'],$form['field_rules_date_released']['und'][0]['value']['date']['#title']);

	// Rules Number
	check_integer($form['rules_field_actnumber']['und'][0]['value']['#value'],$form['rules_field_actnumber']['und'][0]['value']['#title'],'rules_field_actnumber');

	// Rules Year
	check_integer($form['rules_field_rulesyear']['und'][0]['value']['#value'],$form['rules_field_rulesyear']['und'][0]['value']['#title'],'rules_field_rulesyear');
	years($form['rules_field_rulesyear']['und'][0]['value']['#value'],$form['rules_field_rulesyear']['und'][0]['value']['#title'],'rules_field_rulesyear');

	// Commencement date

	check_date_expire($form['rules_field_date']['und'][0]['value']['date']['#value'],$form['rules_field_date']['und'][0]['value']['date']['#title']);

	if ($form['field_rules_avail']['und']['#value'] == 'Online-Available') {
       url_validation($form['field_rules_url']['und'][0]['value']['#value']);
	}


  if ($form['field_rules_avail']['und']['#value'] == 'Downloadable') {
	$filename = $form['field_rules_fileup']['und'][0]['#file'];
	$filename->filename;
    file_upload_validation_D7($filename->filename,$form['field_rules_avail']['und']['#title']);

  }


}


  function rules_presave_validation($node) {
    $reference_url = $node->field_rules_url['und'][0]['value'];
    $node->field_rules_url['und'][0]['value'] = url_validation($reference_url);
  } // function form_presave_validation()

function rules_load_validation() {
  $stat = new set_static_variable();
  $stat->set_edit('yes');
}
